<template>
	<h2>撰写</h2><br />
	<el-form :model="addinform" label-width="120px">
		<el-form-item label="通知作者" >
		      <el-input placeholder="请输入作者" v-model="addinform.informAuther" style="width: 300px;"/>  
		</el-form-item>
		<el-form-item label="通知标题">
		      <el-input placeholder="请输入通知标题" v-model="addinform.informTitle" style="width: 300px;"/>  
		</el-form-item>
		
		<el-form-item label="通知人员">
			 <el-input placeholder="请输入通知人员" v-model="addinform.informTarget" style="width: 300px;"/>  
		</el-form-item>
		<el-form-item label="通知正文">
			<el-input
			    v-model="addinform.informConcent"
			    :autosize="{ minRows: 3, maxRows: 8 }"
			    type="textarea"
			    placeholder="请输入通知正文"
			  />
		</el-form-item>
	    <el-form-item>
			<el-upload
				ref="uploadRef"
				class="upload-demo"
				action="http://localhost:8080/file/upload"
				:auto-upload="true"
				:on-success="successUpload">
                <el-button type="success" >添加附件</el-button>
            </el-upload>		  
		</el-form-item>
		<el-form-item>
			  <el-button type="primary" @click="informInster">发布</el-button>
			  <el-button type="warning" @click="informPre">暂存草稿箱</el-button>
		      <el-button type="info" @click="cannel">取消</el-button>
		</el-form-item>
		
	</el-form>
	
</template>

<script>
	import qs from 'qs'
	export default {
		data(){
			return{
				addinform:{},
				id:0,
				user:0
			}
		},
		methods:{
			test(){
				let u=JSON.parse(sessionStorage.getItem("user"))
				this.user=u.userId
				let str=qs.stringify(this.user)
				this.$axios.get("http://localhost:8080/inform/test?"+str).then(function(res){
				} )
			},
			successUpload(res){
				this.addinform.informAcc=res
				console.log(res)
			},
			informInster(){
				let that=this
				let u=JSON.parse(sessionStorage.getItem("user"))
                this.addinform.userId=u.userId
				let str=qs.stringify(this.addinform)
				this.$axios.get("http://localhost:8080/inform/insert?"+str).then(function(res){
					if(res.data==true){
						alert("发布成功")
					}
					else{
						alert("发布失败")
					}
					
				} )
				},
		    informPre(){
		    	let that=this
				let u=JSON.parse(sessionStorage.getItem("user"))
				this.addinform.userId=u.userId
		    	let str=qs.stringify(that.addinform)
		    	this.$axios.get("http://localhost:8080/inform/informpre?"+str).then(function(res){
		    		if(res.data==true){
		    			alert("保存成功")
		    		}
		    		else{
		    			alert("保存失败")
		    		}
		    		
		    		} )
			},
			cannel(){
				this.$router.push("/index")
			}
		},
		created(){
			
		}
	}
	
</script>

<style>
</style>
